package com.smarthealthring.mm.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.jakewharton.rxbinding2.view.RxView;
import com.smarthealthring.mm.R;
import com.smarthealthring.mm.base.BaseActivity;
import com.smarthealthring.mm.base.IPresenter;
import com.smarthealthring.mm.utils.ComToolBar;
import com.smarthealthring.mm.utils.SPUtils;
import com.xw.repo.BubbleSeekBar;

import butterknife.BindView;

/**
 * 设备类型列表
 * Created by bilibili on 2018/5/15.
 */

public class WeightTagetActivity extends BaseActivity {

    @BindView(R.id.bsb_weight_tar)
    BubbleSeekBar mBsbWeightTar;
    @BindView(R.id.tv_weight_tar)
    TextView mTvWeightTar;
    @BindView(R.id.tv_weight_status)
    TextView mTvWeightStatus;
    int weightFinal;

    @Override
    protected void initComToolBar() {
        ImageView ivLeft = ComToolBar.setleftImg(mContext, R.drawable.back_white);
        RxView.clicks(ivLeft)
                .subscribe(o -> finish());
        ComToolBar.setTitle(mContext, "体重目标设定");
    }

    @Override
    protected int getLayout() {
        return R.layout.act_weight_target;
    }

    @Override
    protected void initEventAndData(@Nullable Bundle savedInstanceState) {
        int spWeight = SPUtils.getInt(SPUtils.WEIGHT_TARGET, 65);
        mTvWeightTar.setText(spWeight + "kg");
        if (spWeight < 55) {
            mTvWeightStatus.setText("目前体重：偏轻");
        } else if (55 <= spWeight && spWeight < 75) {
            mTvWeightStatus.setText("目前体重：标准");
        } else if (spWeight >= 75 && spWeight < 85) {
            mTvWeightStatus.setText("目前体重：偏重");
        } else if (spWeight >= 85) {
            mTvWeightStatus.setText("目前体重：过重");
        }
        Log.e("defualt_weight===", spWeight + "");
        mBsbWeightTar.setProgress(spWeight);
        mBsbWeightTar.setOnProgressChangedListener(new BubbleSeekBar.OnProgressChangedListener() {
            @Override
            public void onProgressChanged(BubbleSeekBar bubbleSeekBar4, int progress, float progressFloat) {
                mTvWeightTar.setText(progress + "kg");
                weightFinal = progress;
                if (progress < 55) {
                    mTvWeightStatus.setText("目前体重：偏轻");
                } else if (55 <= progress && progress < 75) {
                    mTvWeightStatus.setText("目前体重：标准");
                } else if (progress >= 75 && progress < 85) {
                    mTvWeightStatus.setText("目前体重：偏重");
                } else if (progress >= 85) {
                    mTvWeightStatus.setText("目前体重：过重");
                }
                SPUtils.setInt(SPUtils.WEIGHT_TARGET, weightFinal);
            }

            @Override
            public void getProgressOnActionUp(BubbleSeekBar bubbleSeekBar, int progress, float progressFloat) {

            }

            @Override
            public void getProgressOnFinally(BubbleSeekBar bubbleSeekBar, int progress, float progressFloat) {

            }
        });

    }

    @Override
    protected IPresenter createPresenter() {
        return null;
    }

}
